# -*- coding:utf-8 _*-  
import redis
from Data import config

Redis_client = redis.Redis(host=config.redis_host, port=config.redis_port, charset='utf-8')


# redis链表右侧插入数据(传入仓库名称，写入值)
def Redis_Push(DbName, Vaule):
    try:
        Redis_client.rpush(DbName, Vaule)
        print('Write to redis Success,the Dbname:{}'.format(DbName))
    except:
        print('Write to redis Filed,the Dbname:{}'.format(DbName))


# redis链表左侧提取，仓库全部提取完毕后返回None(传入仓库名称)
def Redis_Pop(DbName):
    try:
        Byte_Vaule = Redis_client.lpop(DbName)
        if Byte_Vaule is not None:
            Vaule = str(Byte_Vaule, encoding='utf-8')
            print('Read from redis Success,the Dbname:{}'.format(DbName))
            return Vaule
        else:
            print('None Existent,the Dbname:{}'.format(DbName))
            return None
    except:
        print('Reading Exception occurred from the Dbname:{}'.format(DbName))
        return None


if __name__ == '__main__':
    pass
